package com.xzw.cameratest.bean;

import com.android.business.entity.DataInfo;
import com.android.business.entity.GroupInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * @descripe:
 * @author:111144
 * @date:2020/4/27
 */
public class Node {
    /**
     * 当前节点数据
     */
    public DataInfo data;
    /**
     * 当前节点的父节点
     */
    private Node parent;
    /**
     * 当前节点的父组织id
     */
    private String parentId;
    /**
     * 当前节点的组织id
     */
    private String groupId;
    /**
     * 该节点下面的子节点列表
     */
    private List<Node> childNodes = new ArrayList<>();
    /**
     * 当前节点的暂开状态 是否是暂开
     */
    private boolean isExpand = false;
    /**
     * 当期界定啊是否加载过通道
     */
    private boolean isLoadChannel = false;

    public Node(DataInfo data, String parentId, String groupId) {
        this.data = data;
        this.parentId = parentId;
        this.groupId = groupId;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public String getGroupId() {
        return groupId;
    }

    public void setGroupId(String groupId) {
        this.groupId = groupId;
    }

    public DataInfo getData() {
        return data;
    }

    public void setData(DataInfo data) {
        this.data = data;
    }

    public List<Node> getChildNodes() {
        return childNodes;
    }

    public void setChildNodes(List<Node> childNodes) {
        this.childNodes = childNodes;
    }

    public Node getParent() {
        return parent;
    }

    public void setParent(Node parent) {
        this.parent = parent;
    }

    public boolean isRoot() {
        return getParent() == null;
    }

    public boolean isParentExpand() {
        if (getParent() == null) {
            return true;
        } else {
            return getParent().isExpand();
        }
    }

    public boolean isExpand() {
        return isExpand;
    }

    public void setExpand(boolean expand) {
        isExpand = expand;
        if (!isExpand){

            int size = getChildNodes().size();
            if (size!=0){
                for (Node childNode : getChildNodes()) {
                    childNode.setExpand(isExpand);
                }
            }

        }
    }

    public int getLevel() {
        return getParent() == null ? 0 : parent.getLevel() + 1;
    }

    public String getParentNodeName(){
        if (getParent() == null){
            return "root";
        }else{
            return ((GroupInfo)getParent().getData()).getGroupName();
        }
    }

    public boolean isLoadChannel() {
        return isLoadChannel;
    }

    public void setLoadChannel(boolean loadChannel) {
        isLoadChannel = loadChannel;
    }
}
